package com.rchat.pocmini.activity.login;

import android.content.Context;

import com.aso.common.http.delegate.HttpCallbackImpl;
import com.aso.common.http.utils.HttpUtils;
import com.rchat.pocmini.global.HttpCodeGlobal;
import com.rchat.pocmini.global.RequestParam;
import com.rchat.pocmini.global.UrlsGlobal;
import com.rchat.pocmini.util.SPUtil;


import java.util.HashMap;
import java.util.Map;

/**
 * Created by ljd on 2017/7/26.
 */

public class LoginModelImpl implements LoginContract.Model {

    @Override
    public void login(String account, String pwd, HttpCallbackImpl callback) {
        Map<String, String> param = new HashMap<>();
        param.put("account", account);
        param.put("password", pwd);
        //body = {"code":1011,"data":{"platform":"1","password":"123456","account":"a1","enterprise":"1","version":"1.0"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_1011, param);
        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.LOGIN_URL), body, callback);
    }

    @Override
    public void saveAccount(Context context, String accountKey, String accountValue) {
        SPUtil.put(context, accountKey, accountValue);
    }

    @Override
    public void savePwd(Context context, String pwdKey, String pwdValue) {
        SPUtil.put(context, pwdKey, pwdValue);
    }

}
